﻿namespace PLMonitor;

internal class DYTControl
{
    // FB	V1	V2	V3	V4	SF	AF	φx	φy	FC
    public bool ProcRcvData(byte[] data, int count)
    {
        var index = 0;
        if (count != 16)
        {
            return false;
        }

        if (data[0] != 0xFB || data[15] != 0xFC)
        {
            return false;// 帧头&帧尾
        }

        index ++;
        V1 = (ushort)(data[index] * 256 + data[index+1]);
        index += 2;
        V2 = (ushort)(data[index] * 256 + data[index + 1]);
        index += 2;
        V3 = (ushort)(data[index] * 256 + data[index + 1]);
        index += 2;
        V4 = (ushort)(data[index] * 256 + data[index + 1]);
        index += 2;
        SF = data[index++];
        AF = data[index++];
        AngX = (short)(data[index] * 256 + data[index + 1]) * 0.1f;
        index += 2;
        AngY = (short)(data[index] * 256 + data[index + 1]) * 0.1f;
        index += 2;

        return true;
    }

    // 四通道电压DN值
    public ushort V1 { get; set; }
    public ushort V2 { get; set; }
    public ushort V3 { get; set; }
    public ushort V4 { get; set; }

    public byte SF { get; set; }//状态标志（1：在线性区；2表示不在线性区）

    public string StrSF 
    {
        get 
        {
            if (1 == SF) return "在线性区";
            if (2 == SF) return "在非线性区";
            return $"未知{SF}";
        }
    }

    public byte AF { get; set; }//衰减状态标志（0：表示无衰减；1表示衰减）
    public string StrAF
    {
        get
        {
            if (0 == SF) return "无衰减";
            if (1 == SF) return "衰减";
            return $"未知{AF}";
        }
    }
    // XY方向上的角度
    public float AngX { get; set; }
    public float AngY { get; set; }
}
